package ttstest1.adi_reciepe;

import android.app.Activity;
import android.util.Log;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.speech.tts.TextToSpeech;

import java.util.Locale;
import java.util.Queue;

public class Tts_test1Activity extends Activity implements TextToSpeech.OnInitListener {
	private static final String TAG = "TextToSpeechDemo_1";
	private TextToSpeech tts;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        tts = new TextToSpeech(this,this);
        
        Button sayButton = (Button) findViewById(R.id.sayButton);
        sayButton.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				EditText text = (EditText) findViewById(R.id.editText1);
				Toast.makeText(v.getContext(), text.getText(), Toast.LENGTH_LONG).show();
//				tts.speak(text.getText(), TextToSpeech.QUEUE_FLUSH, null);
				tts.speak(text.getText().toString(),TextToSpeech.QUEUE_FLUSH,null);
			};
		});
    }
    
    // implementation of TextToSpeech.OnInitListener
    public void onInit(int status)
    {
    	if (status != TextToSpeech.SUCCESS){
    		Toast.makeText(null, "Could not init the TTS engine", Toast.LENGTH_LONG);
    		Log.e(TAG, "Could not initialize TextToSpeech.");
    		return;
    	}
    	
    	int result = tts.setLanguage(Locale.US);
    	
    	if (result == TextToSpeech.LANG_MISSING_DATA ||
                result == TextToSpeech.LANG_NOT_SUPPORTED) {
               // Lanuage data is missing or the language is not supported.
                Log.e(TAG, "Language is not available.");
                Button sayButton = (Button) findViewById(R.id.sayButton);
                sayButton.setEnabled(false);
        }   	
    }
}
